package beans

import models.CommentM
import models.ReplyM

data class Comment(
        val id: Int,
        val userId: Int,
        val createTime: Long,
        val content: String,
        var reply: List<Reply>? = null,
        var extent: Map<String, Any>? = null
) {
    companion object{
        fun from(model: CommentM, extent: Map<String, Any>? = null): Comment{
            return Comment(
                    id = model.getInt(CommentM.ID),
                    userId = model.getInt(CommentM.USER_ID),
                    createTime = model.getTimestamp(CommentM.CREATE_TIME).time,
                    content = model[CommentM.CONTENT],
                    extent = extent
            )
        }
    }
}

data class Reply(
        val id: Int,
        val createTime: Long,
        var fromId: Int,
        var toId: Int,
        val content: String,
        val extent: Map<String, Any>? = null
){
    companion object{
        fun from(model: ReplyM, extent: Map<String, Any>? = null): Reply{
            return Reply(
                    id = model.getInt(ReplyM.ID),
                    fromId = model.getInt(ReplyM.FROM_USER_ID),
                    toId = model.getInt(ReplyM.TO_USER_ID),
                    createTime = model.getTimestamp(ReplyM.CRATE_TIME).time,
                    content = model[ReplyM.CONTENT],
                    extent = extent
            )
        }
    }
}